package com.zhao.fishingguideserver.controller;

import com.zhao.fishingguideserver.POJO.Fish;
import com.zhao.fishingguideserver.POJO.Result;
import com.zhao.fishingguideserver.service.FishService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 鱼类信息控制器
 */
@RestController
@RequestMapping("/fish")
public class FishController {
    @Autowired
    private FishService fishService;
    
    /**
     * 查询所有鱼类信息
     */
    @GetMapping("/list")
    public Result<List<Fish>> selectAll() {
        List<Fish> fishes = fishService.selectAll();
        return Result.success(fishes);
    }
    
    /**
     * 根据ID查询鱼类详情
     */
    @GetMapping("/detail/{id}")
    public Result<Fish> getFishDetail(@PathVariable Integer id) {
        Fish fish = fishService.selectById(id);
        if (fish == null) {
            return Result.error("未找到该鱼类信息");
        }
        return Result.success(fish);
    }
    
    /**
     * 根据鱼类名称搜索
     */
    @GetMapping("/search")
    public Result<List<Fish>> searchFish(@RequestParam String keyword) {
        List<Fish> fishes = fishService.searchByKeyword(keyword);
        return Result.success(fishes);
    }
    
    /**
     * 根据栖息地和食性筛选
     */
    @GetMapping("/filterByHabitat")
    public Result<List<Fish>> filterByHabitat(@RequestParam String habitat) {
        List<Fish> fishes = fishService.filterByHabitat(habitat);
        return Result.success(fishes);
    }
    
    /**
     * 根据分布区域筛选
     */
    @GetMapping("/filterByDistribution")
    public Result<List<Fish>> filterByDistribution(@RequestParam String distribution) {
        List<Fish> fishes = fishService.filterByDistribution(distribution);
        return Result.success(fishes);
    }
}
